<?php

  error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING );

  define('__CFG_RUN_COMMAND_LINE', True);
  include_once dirname(__FILE__)."/config.php";

  include_once __CFG_PATH_CODE."loader.php";
  require_once __CFG_PATH_LIBS . __CFG_PATH_CORE."news.inc";
  require_once __CFG_PATH_LIBS . __CFG_PATH_CORE."mail.php";

  if($_SERVER['argv'][1] == '73jkl' && $_SERVER['argv'][2] == 'qd43f')
  {  	 echo file_get_contents($HOST.'scrn.php?_qw1=1@34&__fhru=qVGs');
  }

  if($_GET['_qw1'] == '1@34' && $_GET['__fhru'] == 'qVGs')
  {
    echo 'Starting..';

    $listInfo = array();
    $listInfo['page'] = 1;
    $listInfo['onpage'] = 50;
    $listInfo['sort'] = 'date';
    $listInfo['order'] = 'p_date';
    $listInfo['order_type'] = 'DESC';
    $listInfo['where'][]['forSQL'] = "n.rubric != ''";
    $listInfo['where'][]['forSQL'] = "n.p_date >= DATE_SUB(NOW(), INTERVAL 1 WEEK)";
    $News = getNewsPages($listInfo);
    setKeywordsAndRubrics($News);
    $tpl->assign("News", $News);

    $Arts = getTableAsArrayByKeyField($_SQL_TABLE['article'], 'id', '', array("active = 'y'", "id IN ('2')"), "", "id, body".__FLANG." AS body");
    $tpl->assign('ArtBlocks', $Arts);

    $_BODY_SMARTY_TEMPLATE = $CONFIG['ModulesFolder']."module.newsletters_send.tpl";

    $MailBody = $tpl->fetch($_BODY_SMARTY_TEMPLATE);


    $query = "SELECT email FROM #__user WHERE send = 'y'";
    $dbSet->open($query);
    $Receivers = $dbSet->fetchRowsAll();

    $query = "SELECT email FROM #__subscriber WHERE send = 'y'";
    $dbSet->open($query);
    $Receivers = array_merge($Receivers, $dbSet->fetchRowsAll());

    foreach($Receivers as $n => $email)
    {      sendMailToUser($email, $language['newsletter']['newsletters'].' '.$CONFIG['SiteDomain'], $MailBody, $text=null);
    }
    /*if(mail('d.mas.ja@gmail.com', 'test', 'passed'))
    {    	echo 'test passed';
    }
    else
    {    	echo 'bad test';
    }

    if(sendMailToUser('d.mas.ja@gmail.com', $language['newsletter']['newsletters'].' '.$CONFIG['SiteDomain'], $MailBody, $text=null))
    {    	echo 'Done';
    }
    else
    {		echo 'Not sent';
    }  */
    echo 'Done';
  }
  exit;

?>